#include "widget.h"
#include "ui_widget.h"

#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QDateTime timeold = ui->dateTimeEdit->dateTime();
    QDateTime timenew = ui->dateTimeEdit_2->dateTime();
    // 计算日期差
    //int days = timeold.daysTo(timenew);
    int secs = timeold.secsTo(timenew);
    int days = secs / 3600 /24;
    int hours = secs / 3600 % 24;
    // 设置label内容
    QString text = QString("日期相差") + QString::number(days) + QString("天零")
                   + QString::number(hours) + QString("个小时");
    ui->label->setText(text);
}
